import {useState} from "react";

//子传父
//核心：在子组件中调用父组件中的函数并传递实参
const Son = ({getSonMsg}) => {
    const sonMsg = 'this is son message!'
    return (
        <div>
            <h2>this is son</h2>
            <button onClick={() => {
                getSonMsg(sonMsg)
            }}>给父传递的数据
            </button>
        </div>
    )
}
export const App = () => {
    const [msg, setMsg] = useState('')
    const getMsg = (msg) => {
        setMsg(msg)
    }
    return (
        <div>
            <h2>this is app</h2>
            <p>{msg}</p>
            <Son getSonMsg={getMsg}/>
        </div>
    )
}
